home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / domacnost a kancelar / joomla / Joomla_1.5.4-Stable-Full_Package.exe / plugins / search / sections.php < prev    next >
PHP Script  |  2008-07-06  |  3KB  |  104 lines

  1. <?php
  2. /**
  3.  * @version        $Id: sections.php 10381 2008-06-01 03:35:53Z pasamio $
  4.  * @package        Joomla
  5.  * @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
  6.  * @license        GNU/GPL, see LICENSE.php
  7.  * Joomla! is free software. This version may have been modified pursuant
  8.  * to the GNU General Public License, and as distributed it includes or
  9.  * is derivative of works licensed under the GNU General Public License or
  10.  * other free or open source software licenses.
  11.  * See COPYRIGHT.php for copyright notices and details.
  12.  */
  13.  
  14. // no direct access
  15. defined( '_JEXEC' ) or die( 'Restricted access' );
  16.  
  17. $mainframe->registerEvent( 'onSearch', 'plgSearchSections' );
  18. $mainframe->registerEvent( 'onSearchAreas', 'plgSearchSectionAreas' );
  19.  
  20. JPlugin::loadLanguage( 'plg_search_sections' );
  21.  
  22. /**
  23.  * @return array An array of search areas
  24.  */
  25. function &plgSearchSectionAreas() {
  26.     static $areas = array(
  27.         'sections' => 'Sections'
  28.     );
  29.     return $areas;
  30. }
  31.  
  32. /**
  33. * Sections Search method
  34. *
  35. * The sql must return the following fields that are used in a common display
  36. * routine: href, title, section, created, text, browsernav
  37. * @param string Target search string
  38. * @param string mathcing option, exact|any|all
  39. * @param string ordering option, newest|oldest|popular|alpha|category
  40.  * @param mixed An array if restricted to areas, null if search all
  41. */
  42. function plgSearchSections( $text, $phrase='', $ordering='', $areas=null )
  43. {
  44.     $db        =& JFactory::getDBO();
  45.     $user    =& JFactory::getUser();
  46.  
  47.     require_once(JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
  48.  
  49.     if (is_array( $areas )) {
  50.         if (!array_intersect( $areas, array_keys( plgSearchSectionAreas() ) )) {
  51.             return array();
  52.         }
  53.     }
  54.  
  55.     // load plugin params info
  56.      $plugin =& JPluginHelper::getPlugin('search', 'sections');
  57.      $pluginParams = new JParameter( $plugin->params );
  58.  
  59.     $limit = $pluginParams->def( 'search_limit', 50 );
  60.  
  61.     $text = trim( $text );
  62.     if ($text == '') {
  63.         return array();
  64.     }
  65.  
  66.     switch ( $ordering ) {
  67.         case 'alpha':
  68.             $order = 'a.name ASC';
  69.             break;
  70.  
  71.         case 'category':
  72.         case 'popular':
  73.         case 'newest':
  74.         case 'oldest':
  75.         default:
  76.             $order = 'a.name DESC';
  77.     }
  78.  
  79.     $text    = $db->Quote( '%'.$db->getEscaped( $text, true ).'%', false );
  80.     $query    = 'SELECT a.title AS title, a.description AS text,'
  81.     . ' "" AS created,'
  82.     . ' "2" AS browsernav,'
  83.     . ' a.id AS secid'
  84.     . ' FROM #__sections AS a'
  85.     . ' WHERE ( a.name LIKE '.$text
  86.     . ' OR a.title LIKE '.$text
  87.     . ' OR a.description LIKE '.$text.' )'
  88.     . ' AND a.published = 1'
  89.     . ' AND a.access <= '.(int) $user->get( 'aid' )
  90.     . ' GROUP BY a.id'
  91.     . ' ORDER BY '. $order
  92.     ;
  93.     $db->setQuery( $query, 0, $limit );
  94.     $rows = $db->loadObjectList();
  95.  
  96.     $count = count( $rows );
  97.     for ( $i = 0; $i < $count; $i++ )
  98.     {
  99.         $rows[$i]->href     = ContentHelperRoute::getSectionRoute($rows[$i]->secid);
  100.         $rows[$i]->section     = JText::_( 'Section' );
  101.     }
  102.  
  103.     return $rows;
  104. }